<template>
  <div class="container">
    <div class="articleContainer">
      <el-form :model="form">
        <el-form-item label="" :label-width="formLabelWidth">
          <el-input
            v-model="form.articleTypename"
            autocomplete="off"
            placeholder="文章标题"
          ></el-input>
        </el-form-item>
        <el-form-item label="" :label-width="formLabelWidth">
          <el-input
            v-model="form.articleTypename"
            autocomplete="off"
            placeholder="文章简介"
          ></el-input>
        </el-form-item>

       
        <el-form-item label="" :label-width="formLabelWidth">
          <el-input
            v-model="form.articleTypename"
            autocomplete="off"
            placeholder="文章作者"
          ></el-input>
        </el-form-item>
          <el-form-item label="" :label-width="formLabelWidth">
          <el-select
            v-model="form.region"
            placeholder="请选择文章类型"
          >
            <el-option label="新闻时事" value="shanghai"></el-option>
            <el-option label="公司动态" value="beijing"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="" :label-width="formLabelWidth">
          <!-- markdown -->
          <div>
            <mavon-editor
              v-model="content"
              ref="md"
              @change="change"
              @imgAdd="$imgAdd"
              style="min-height: 600px"
            />
          </div>
        </el-form-item>

         <el-form-item label="" :label-width="formLabelWidth">
          <el-upload
            class="upload-demo"
           
            drag
            action="https://jsonplaceholder.typicode.com/posts/"
            multiple
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              文章封面图 将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>
      


      
      </el-form>
      <div slot="footer" class="dialog-footer">
         <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
// 导入组件 及 组件样式
import { mavonEditor } from "mavon-editor";
import "mavon-editor/dist/css/index.css";
export default {
  components: {
    mavonEditor, //mavon-editor组件
  },
  data() {
    return {
      content: "", // 输入的markdown
      html: "", // 转成的html
      form: {
        region: "",
        delivery: false,
      },
      formLabelWidth: "50px",
    };
  },
  methods: {
    //取消
    cancel() {
      this.$router.push("/ArticleManagement/Article/ArticleNotPublished");
    },
    //确定
    confirm(){

    },
    change(value, render) {
      //实时获取转成html的数据
      this.html = render;
      console.log(this.html);
    },
    // 将图片上传到服务器，返回地址替换到md中
    $imgAdd(pos, $file) {
      let formdata = new FormData();
      formdata.append("image", $file);
      this.$ajax({
        url: "http://local.basic.com/index.php?r=markdown/upload",
        method: "post",
        data: formdata,
      }).then((data) => {
        //将返回的url替换到文本原位置
        if (data.data.success == 1) {
          this.$refs.md.$img2Url(pos, data.data.url);
          console.log(data.data.url);
        }
      });
    },
  },
};
</script>

<style>
.container {
  display: flex;
  /* align-items: center; */
  justify-content: center;
  height: 100vh;
}

.clearfix {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 35px;
}
.el-form-item__content {
  display: flex;
  justify-content: flex-end;
}
.dialog-footer {
  float: right;
}
.el-select{
    -webkit-appearance: none;
    background-color: #FFF;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
}

</style>